<?php
/**
 * 下午茶申请单查询
 * @package  htdocs
 * @subpackage  quanliadmin
 * @author   allen.qiang  <allen.qiang@fistforward.com> 2015-01-14 allen.qiang FUN-AC-0028-下午茶项目
 */

quanli_require('module/base/bill/billSearch.class.php');

class pa_applySearch {

    public function execute() {

        global $G_PGLOB;

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch ($_REQUEST['operFlg']) {

                case 1: //显示列表页面
                    $this->applySearchList();
                    break;
                case 2: //显示添加采购单页面
                    $this->addApply();
                    break;
                case 3: //显示采购单入库页面
                    $this->applyWarehousing();
                    break;
                default:
                    $G_PGLOB->smarty->assign('msg', '参数错误');
                    $G_PGLOB->smarty->display('comm/error.tpl');
            }
        }
    }

    /**
     * 显示列表页面
     */
    private function applySearchList() {
        global $G_PGLOB;
        //当前时间
        $currentDate = date('Y-m-d');
        $G_PGLOB->smarty->assign('currentDate',$currentDate);
        $G_PGLOB->smarty->display('production/applySearch.tpl');
    }

    /**
     * 显示添加采购单页面
     */
    private function addApply() {
        global $G_PGLOB;
        //当前时间后一天
        $currentDate = date('Y-m-d',strtotime('+1 day'));
        $G_PGLOB->smarty->assign('currentDate',$currentDate);
        $G_PGLOB->smarty->display('production/applyAdd.tpl');
    }

    /**
     * 显示采购单入库页面
     */
    private function applyWarehousing() {
        global $G_PGLOB;

        $applyID=$_REQUEST["applyID"];
        $sql = "SELECT * FROM `dunch_apply_detail` WHERE apply_id='".$applyID."'";
        $dunch_apply_detail=$G_PGLOB->DBCA->stmt_query($sql);
        $item_array = array();
        foreach($dunch_apply_detail as &$item) {

            $item_array[] = array(
                'apply_id' => $item->apply_id,
                'product_code' => $item->product_code,
                'product_name' => $item->product_name,
                'apply_amount' => $item->apply_amount
            );
        }
        $G_PGLOB->smarty->assign('applyID',$applyID);
        $G_PGLOB->smarty->assign('dunch_apply_detail',$item_array);
        $G_PGLOB->smarty->display('production/applyWarehousing.tpl');
    }

}
